package org.spring.springboot.controller;

import java.util.HashMap;
import java.util.Map;

import org.spring.springboot.domain.City;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/** 
* @author 作者 zhujf: 
* @version 创建时间：2017年10月11日 下午2:53:00 
* 
*/
@Controller
@RequestMapping("/test")
public class AddController {

	@RequestMapping("/add")
	public String add(City city){
		System.out.println(city.getCityName()+":"+city.getId());
		
		return "";
	}
	@RequestMapping("/getinfo")
	public String get(Model model){
		Map<String,Object> map = new HashMap<String,Object>();
		City city = new City();
    	city.setId(1L);
    	city.setCityName("beijing");
    	model.addAttribute(city);
		
		return "getinfo";
	}
	
	//实现数据的双向绑定，后台要这么写
	  @RequestMapping(value = "/updateSave", method = RequestMethod.GET)
	  public ModelAndView update( @ModelAttribute("a") ModelMap a) {
		  
		  City city = new City();
	    	city.setId(1L);
	    	city.setCityName("beijing"); 
		//update代表viewname  
	  return new ModelAndView("update", "a", city);
	  }
	
	
	
	
}
